package com.css.fxfzysx.modules.vaolEngineering.repository.impl;

import com.css.fxfzysx.modules.lifeline.entity.newEntity.SmxUpNetworkEntity;
import com.css.fxfzysx.modules.vaolEngineering.entity.ContinuousWeldingEntity;
import com.css.fxfzysx.modules.vaolEngineering.entity.InterfaceWeldingEntity;
import com.css.fxfzysx.modules.vaolEngineering.entity.PipelineDamageRateEntity;
import com.css.fxfzysx.modules.vaolEngineering.param.update.UpNetwork1Param;
import com.css.fxfzysx.modules.vaolEngineering.param.update.UpNetwork2Param;
import com.css.fxfzysx.modules.vaolEngineering.param.update.UpNetwork3Param;
import com.css.fxfzysx.modules.vaolEngineering.repository.UpNetworkRepository;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.awt.image.Kernel;
import java.util.List;

@Service
public class UpNetworkRepositoryImpl implements UpNetworkRepository {

    @Resource
    private JdbcTemplate jdbcTemplate;

    @Resource
    private NamedParameterJdbcTemplate namedParameterJdbcTemplate;

    @Override
    public boolean saveUpNetWork(SmxUpNetworkEntity it) {
        String sql = "insert into czt_smx_up_network values (:id,:upId,:type,:startId,:endId,:longitude,:latitude,:length,:siteClassification,:material,:diameter,:intensity,:year,:joint,:disasterRate6,:disasterRate7,:disasterRate8,:disasterRate9,:disasterRate10,:materialType,:elasticityModulus,:yieldLimitStress,:strengthLimitStress,:permissibleStrain,:thickness,:pressure,:jointy,:allowableElongation,:site,:liquefaction6,:liquefaction7,:liquefaction8,:liquefaction9,:seismicSubsidence6,:seismicSubsidence7,:seismicSubsidence8,:seismicSubsidence9,:depth,:maxSpeed,:maxAccelaration,:longitudinalWaveVelocity,:transverseWaveVelocity,:maxPipelineStrain,:crossSectionalArea,:earthquakeWavelength,:earthquakewaveIncidentAngle,:poissonsRatio,:lCos,:s,:ep,:zdyl,:wqdcsdjl,:wj,:i,:soilbulkDensity1,:burialDepth,:soilstaticPressureCoefficient,:pipeOd,:insideDiameter,:tBuriedDepth,:linearExpansionCoefficient,:correctionFactor,:temperatureDifference,:internalPressure,:curvature,:soilLateralPressure,:soilbulkDensity2,:soilBurialDepth,:adjustmentCoefficient1,:adjustmentCoefficient2,:groundMotionSpeed,:surfaceWaveVelocity,:interfaceReductionCoefficient,:singlePipeLength,:soilPressure,:internalWaterPressure,:ipai,:wqylZx,:jylHx,:txjtcjyl,:wjT,:zylZxT,:jylHxT,:wdyl,:wallThickness,:hxlyl,:zxlyl,:ps,:hxyyl,:zxyyl,:allSumZx,:allSumHx,:permissibleTress,:lxBreakState,:lxBreakStateCorrect,:result,:er,:et,:lt,:jkPs,:es,:compressDeform,:tensileStrain,:strainDeform,:combineAxialStrain,:combineAxialStrainCorrect,:jkDamage,:jkDamageCorrect,:jkLCos,:delFlag,:tableId,ST_GeometryFromText(:geom,4490),:name,:versionId,:disasterRate6State,:disasterRate7State,:disasterRate8State,:disasterRate9State,:disasterRate10State,:serialNumber,:foundationZCoefficient,:note,:disasterRate6StateCorrect,:disasterRate7StateCorrect,:disasterRate8StateCorrect,:disasterRate9StateCorrect,:disasterRate10StateCorrect,:createUser,:createTime,:updateUser,:updateTime,:extends1,:extends2,:extends3,:extends4,:extends5,:extends6,:extends7,:extends8,:extends9,:extends10)";
        SqlParameterSource source = new BeanPropertySqlParameterSource(it);
        return namedParameterJdbcTemplate.update(sql, source) > 0;
    }

    @Override
    public List<SmxUpNetworkEntity> getByVersionId(String versionId) {
        try {
            String sql = "select * from czt_smx_up_network where version_id = '"+versionId+"'";
            return jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(SmxUpNetworkEntity.class));
        } catch (DataAccessException e) {
            return null;
        }
    }

    @Override
    public void savePseVulnerabilityResult(SmxUpNetworkEntity it) {
        jdbcTemplate.update("update czt_smx_up_network set disaster_rate6=?,disaster_rate7=?,disaster_rate8=?,disaster_rate9=?,disaster_rate10=?,disaster_rate6_state=?,disaster_rate7_state=?,disaster_rate8_state=?,disaster_rate9_state=?,disaster_rate10_state=?,disaster_rate6_state_correct=?,disaster_rate7_state_correct=?,disaster_rate8_state_correct=?,disaster_rate9_state_correct=?,disaster_rate10_state_correct=? where id = ?",
                it.getDisasterRate6(),it.getDisasterRate7(),it.getDisasterRate8(),it.getDisasterRate9(),it.getDisasterRate10(),it.getDisasterRate6State(),it.getDisasterRate7State(),it.getDisasterRate8State(),it.getDisasterRate9State(),it.getDisasterRate10State(),it.getDisasterRate6StateCorrect(),it.getDisasterRate7StateCorrect(),it.getDisasterRate8StateCorrect(),it.getDisasterRate9StateCorrect(),it.getDisasterRate10StateCorrect(),it.getId());
    }

    @Override
    public void saveContinuousWeldingResult(SmxUpNetworkEntity cw) {
        jdbcTemplate.update("update czt_smx_up_network set max_pipeline_strain=?,l_cos=?,s=?,ep=?,zdyl=?,wqdcsdjl=?,wj=?,i=?,ipai=?,wqyl_zx=?,jyl_hx=?,wj_t=?,zyl_zx_t=?,jyl_hx_t=?,wdyl=?,wall_thickness=?,hxlyl=?,zxlyl=?,ps=?,hxyyl=?,zxyyl=?,all_sum_zx=?,all_sum_hx=?,permissible_tress=?,adjustment_coefficient1=?,adjustment_coefficient2=?,lx_break_state=?,lx_break_state_correct=?,txjtcjyl=?,permissible_tress_correct=? where id=?",
                cw.getMaxPipelineStrain(),cw.getLCos(),cw.getS(),cw.getEp(),cw.getZdyl(),cw.getWqdcsdjl(),cw.getWj(),cw.getI(),cw.getIpai(),cw.getWqylZx(),cw.getJylHx(),cw.getWjT(),cw.getZylZxT(),cw.getJylHxT(),cw.getWdyl(),cw.getWallThickness(),cw.getHxlyl(),cw.getZxlyl(),cw.getPs(),cw.getHxyyl(),cw.getZxyyl(),cw.getAllSumZx(),cw.getAllSumHx(),cw.getPermissibleTress(),cw.getAdjustmentCoefficient1(),cw.getAdjustmentCoefficient2(),cw.getLxBreakState(),cw.getLxBreakStateCorrect(),cw.getTxjtcjyl(),cw.getPermissibleTressCorrect(),cw.getId());
    }

    @Override
    public void saveInterfaceWeldingResult(SmxUpNetworkEntity ie) {
        jdbcTemplate.update("update czt_smx_up_network set jk_l_cos=?,result=?,er=?,et=?,lt=?,jk_ps=?,es=?,compress_deform=?,tensile_strain=?,strain_deform=?,combine_axial_strain=?,combine_axial_strain_correct=?,jk_damage=?,jk_damage_correct=? where id = ?",
                ie.getJkLCos(),ie.getResult(),ie.getEr(),ie.getEt(),ie.getLt(),ie.getJkPs(),ie.getEs(),ie.getCompressDeform(),ie.getTensileStrain(),ie.getStrainDeform(),ie.getCombineAxialStrain(),ie.getCombineAxialStrainCorrect(),ie.getJkDamage(),ie.getJkDamageCorrect(),ie.getId());
    }

    @Override
    public SmxUpNetworkEntity getByTableId(String id) {
        String sql = "select * from czt_smx_up_network where table_id = '"+id+"'";
        return jdbcTemplate.queryForObject(sql,new BeanPropertyRowMapper<>(SmxUpNetworkEntity.class));
    }

    @Override
    public void updateSimpleModelById(UpNetwork1Param entity) {
        jdbcTemplate.update("update czt_smx_up_network set material=?,site_classification=?,joint=?,diameter=?,disaster_rate6=?,disaster_rate6_state=?,disaster_rate7=?,disaster_rate7_state=?,disaster_rate8=?,disaster_rate8_state=?,disaster_rate9=?,disaster_rate9_state=?,disaster_rate10=?,disaster_rate10_state=? where id =?",
                entity.getMaterial(),entity.getSiteClassification(),entity.getJoint(),entity.getDiameter(),entity.getDisasterRate6(),entity.getDisasterRate6State(),entity.getDisasterRate7(),entity.getDisasterRate7State(),entity.getDisasterRate8(),entity.getDisasterRate8State(),entity.getDisasterRate9(),entity.getDisasterRate9State(),entity.getDisasterRate10(),entity.getDisasterRate10State(),entity.getId());
    }

    @Override
    public void updateContinuousWeldingById(UpNetwork2Param entity) {
        jdbcTemplate.update("update czt_smx_up_network set material=?,max_speed=?,max_accelaration=?,diameter=?,longitudinal_wave_velocity=?,transverse_wave_velocity=?,elasticity_modulus=?,cross_sectional_area=?,foundation_z_coefficient=?,earthquake_wavelength=?,earthquakewave_incident_angle=?,poissons_ratio=?,soilbulk_density1=?,burial_depth=?,soilstatic_pressure_coefficient=?,pipe_od=?,inside_diameter=?,t_buried_depth=?,linear_expansion_coefficient=?,correction_factor=?,temperature_difference=?,internal_pressure=?,curvature=?,wall_thickness=?,yield_limit_stress=?,strength_limit_stress=?,adjustment_coefficient1=?,adjustment_coefficient2=?,lx_break_state_correct=?,max_pipeline_strain=?,l_cos=?,s=?,ep=?,zdyl=?,wqdcsdjl=?,wj=?,i=?,ipai=?,wqyl_zx=?,jyl_hx=?,txjtcjyl=?,wj_t=?,zyl_zx_t=?,jyl_hx_t=?,wdyl=?,hxlyl=?,zxlyl=?,soilbulk_density2=?,soil_burial_depth=?,soil_lateral_pressure=?,ps=?,hxyyl=?,zxyyl=?,all_sum_zx=?,all_sum_hx=?,permissible_tress=?,permissible_tress_correct=?,lx_break_state=? where id=?",
                entity.getMaterial(),entity.getMaxSpeed(),entity.getMaxAccelaration(),entity.getDiameter(),entity.getLongitudinalWaveVelocity(),entity.getTransverseWaveVelocity(),entity.getElasticityModulus(),entity.getCrossSectionalArea(),entity.getFoundationZCoefficient(),entity.getEarthquakeWavelength(),entity.getEarthquakewaveIncidentAngle(),entity.getPoissonsRatio(),entity.getSoilbulkDensity1(),entity.getBurialDepth(),entity.getSoilstaticPressureCoefficient(),entity.getPipeOd(),entity.getInsideDiameter(),entity.getTBuriedDepth(),entity.getLinearExpansionCoefficient(),entity.getCorrectionFactor(),entity.getTemperatureDifference(),entity.getInternalPressure(),entity.getCurvature(),entity.getWallThickness(),entity.getYieldLimitStress(),entity.getStrengthLimitStress(),entity.getAdjustmentCoefficient1(),entity.getAdjustmentCoefficient2(),entity.getLxBreakStateCorrect(),entity.getMaxPipelineStrain(),entity.getLCos(),entity.getS(),entity.getEp(),entity.getZdyl(),entity.getWqdcsdjl(),entity.getWj(),entity.getI(),entity.getIpai(),entity.getWqylZx(),entity.getJylHx(),entity.getTxjtcjyl(),entity.getWjT(),entity.getZylZxT(),entity.getJylHxT(),entity.getWdyl(),entity.getHxlyl(),entity.getZxlyl(),entity.getSoilbulkDensity2(),entity.getSoilBurialDepth(),entity.getSoilLateralPressure(),entity.getPs(),entity.getHxyyl(),entity.getZxyyl(),entity.getAllSumZx(),entity.getAllSumHx(),entity.getPermissibleTress(),entity.getPermissibleTressCorrect(),entity.getLxBreakState(),entity.getId());
    }

    @Override
    public void updateInterfaceTypeById(UpNetwork3Param entity) {
        jdbcTemplate.update("update czt_smx_up_network set elasticity_modulus=?,cross_sectional_area=?,earthquake_wavelength=?,earthquakewave_incident_angle=?,ground_motion_speed=?,foundation_z_coefficient=?,surface_wave_velocity=?,interface_reduction_coefficient=?,single_pipe_length=?,depth=?,pipe_od=?,wall_thickness=?,soilbulk_density2=?,soil_pressure=?,curvature=?,internal_water_pressure=?,poissons_ratio=?,combine_axial_strain=?,combine_axial_strain_correct=?,allowable_elongation=?,jk_damage=?,jk_damage_correct=?,jk_l_cos=?,result=?,er=?,et=?,jk_ps=?,lt=?,es=?,compress_deform=?,tensile_strain=?,thickness=?,strain_deform=? where id=?",
                entity.getElasticityModulus(),entity.getCrossSectionalArea(),entity.getEarthquakeWavelength(),entity.getEarthquakewaveIncidentAngle(),entity.getGroundMotionSpeed(),entity.getFoundationZCoefficient(),entity.getSurfaceWaveVelocity(),entity.getInterfaceReductionCoefficient(),entity.getSinglePipeLength(),entity.getDepth(),entity.getPipeOd(),entity.getWallThickness(),entity.getSoilbulkDensity2(),entity.getSoilPressure(),entity.getCurvature(),entity.getInternalWaterPressure(),entity.getPoissonsRatio(),entity.getCombineAxialStrain(),entity.getCombineAxialStrainCorrect(),entity.getAllowableElongation(),entity.getJkDamage(),entity.getJkDamageCorrect(),entity.getJkLCos(),entity.getResult(),entity.getEr(),entity.getEt(),entity.getJkPs(),entity.getLt(),entity.getEs(),entity.getCompressDeform(),entity.getTensileStrain(),entity.getThickness(),entity.getStrainDeform(),entity.getId());
    }
}
